package com.wfg.nettydemo.delaywork;

import io.netty.util.HashedWheelTimer;
import org.junit.Test;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @author wufagang
 * @description
 * @date 2023年03月03日 20:33
 */

public class HashedWheelTimerDemo {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(1);

        HashedWheelTimer timer = new HashedWheelTimer(1, TimeUnit.SECONDS, 16);
        System.out.println("current timestamp="+System.currentTimeMillis());
        timer.newTimeout((timeout) -> {
            System.out.println("task execute,current timestamp="+System.currentTimeMillis());
            countDownLatch.countDown();
        }, 2000, TimeUnit.MILLISECONDS);

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        timer.stop();
    }


}
